package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPurchaseRequisition;
import com.ruoyi.system.service.ISysPurchaseRequisitionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import oshi.driver.windows.DeviceTree;

/**
 * 【合同状态-信息录入】Controller
 * 
 * @author ruoyi
 * @date 2022-03-14
 */
@Api(tags = "合同状态")
@RestController
@RequestMapping("/lifecycle/requisition")
public class SysPurchaseRequisitionController extends BaseController
{
    @Autowired
    private ISysPurchaseRequisitionService sysPurchaseRequisitionService;

    /**
     * 查询【合同信息】列表
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPurchaseRequisition sysPurchaseRequisition)
    {
        startPage();
        List<SysPurchaseRequisition> list = sysPurchaseRequisitionService.selectSysPurchaseRequisitionList(sysPurchaseRequisition);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysPurchaseRequisition sysPurchaseRequisition)
    {
        List<SysPurchaseRequisition> list = sysPurchaseRequisitionService.selectSysPurchaseRequisitionList(sysPurchaseRequisition);
        ExcelUtil<SysPurchaseRequisition> util = new ExcelUtil<SysPurchaseRequisition>(SysPurchaseRequisition.class);
        return util.exportExcel(list, "【合同信息】数据");
    }

    /**
     * 获取【合同信息】详细信息
     */

    @PreAuthorize("@ss.hasPermi('system:requisition:query')")
    @GetMapping(value = "/{deviceId}")

    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return AjaxResult.success(sysPurchaseRequisitionService.selectSysPurchaseRequisitionByDeviceId(deviceId));
    }

    /**
     * 新增【合同信息】
     */
    @PreAuthorize("@ss.hasPermi('lifecycle:requisition:add')")
    @Log(title = "【新增合同信息】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysPurchaseRequisition sysPurchaseRequisition)
    {
        return toAjax(sysPurchaseRequisitionService.insertSysPurchaseRequisition(sysPurchaseRequisition));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('lifecycle:requisition:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPurchaseRequisition sysPurchaseRequisition)
    {
        return toAjax(sysPurchaseRequisitionService.updateSysPurchaseRequisition(sysPurchaseRequisition));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('lifecycle:requisition:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(sysPurchaseRequisitionService.deleteSysPurchaseRequisitionByDeviceIds(deviceIds));
    }
}
